package com.xls.box2023.tuiguangyouxi;


import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzz.bottomencapsulation.customview.statelayout.StateLayout;
import com.lzz.bottomencapsulation.statusbar.StatusBarHeightView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xls.box2023.Consts.IntentConsts;
import com.xls.box2023.R;
import com.xls.box2023.customcontrol.RoundedImageView;
import com.xls.box2023.entity.JiFenMingXiEntity;
import com.xls.box2023.mvp.MVPBaseActivity;
import com.xls.xrecyclerview.XRecyclerView;

import androidx.recyclerview.widget.LinearLayoutManager;


/**
 * MVPPlugin
 */

public class TuiGuangYouXiActivity extends MVPBaseActivity<TuiGuangYouXiContract.View, TuiGuangYouXiPresenter> implements TuiGuangYouXiContract.View, View.OnClickListener {

    private TextView title_text;
    private TextView title_back;
    private RelativeLayout title_rl;
    private StatusBarHeightView title_rl_content;
    private XRecyclerView tgyx_list;
    private RoundedImageView youxi_icon;
    private TextView youxi_name;
    private TextView youxi_org;
    private TextView youxi_shouyi_jinri;
    private TextView youxi_shouyi_zong;
    private RelativeLayout item_youxi;
    private StateLayout tgyx_statelayout;

    public static void start(Context context, String appid, String packagename,String startTime,String stopTime, JiFenMingXiEntity data) {
        Intent intent =new Intent(context,TuiGuangYouXiActivity.class);
        intent.putExtra(IntentConsts.id,appid);
        intent.putExtra(IntentConsts.packageName,packagename);
        intent.putExtra(IntentConsts.data,data);
        intent.putExtra(IntentConsts.StartTime,startTime);
        intent.putExtra(IntentConsts.StopTime,stopTime);
        context.startActivity(intent);
    }

    @Override
    public int getView() {
        return R.layout.activity_tuiguangyouxi;
    }

    @Override
    public void initView() {

        title_text = findViewById(R.id.title_text);
        title_back = findViewById(R.id.title_back);
        title_rl = findViewById(R.id.title_rl);
        title_rl_content = findViewById(R.id.title_rl_content);
        tgyx_list = findViewById(R.id.tgyx_list);
        title_text.setText("收益明细");
        title_back.setOnClickListener(this);
        youxi_icon = findViewById(R.id.youxi_icon);
        youxi_name = findViewById(R.id.youxi_name);
        youxi_org = findViewById(R.id.youxi_org);
        youxi_shouyi_jinri = findViewById(R.id.youxi_shouyi_jinri);
        youxi_shouyi_zong = findViewById(R.id.youxi_shouyi_zong);
        item_youxi = findViewById(R.id.item_youxi);

        //        游戏图标
        JiFenMingXiEntity viewData=  mPresenter.getJiFenMingXi();
        if (!TextUtils.isEmpty(viewData.getPicture())){
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .cacheInMemory(false)// 设置下载的图片是否缓存在内存中
                    .cacheOnDisk(true)// 设置下载的图片是否缓存在SD卡中
                    .build();
            ImageLoader.getInstance().displayImage(viewData.getPicture(),youxi_icon, options);
        }
        if (!TextUtils.isEmpty(viewData.getAppName())){
            youxi_name.setText(viewData.getAppName());
        }

        if (!TextUtils.isEmpty(viewData.getTenantName())){
            youxi_org.setText(viewData.getTenantName());
        }

        youxi_shouyi_jinri.setText("今日收益："+viewData.getRefferScoreTodayStr()+" 元宝");
        youxi_shouyi_zong.setText("总收益："+viewData.getRefferScoreTotalStr()+" 元宝");

        tgyx_list.setLoadingMoreEnabled(false);
        tgyx_list.setLoadingListener(mPresenter.getLoadingListener());
        tgyx_list.setLayoutManager(new LinearLayoutManager(this));
        tgyx_list.setAdapter(mPresenter.getAdapter());
        tgyx_statelayout = findViewById(R.id.tgyx_statelayout);
        tgyx_statelayout.showProgressView();
        tgyx_statelayout.setErrorAndEmptyAction(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tgyx_list.refresh();
            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.title_back) {
            finish();
        }
    }

    @Override
    public XRecyclerView getListView() {
        return tgyx_list;
    }

    @Override
    public StateLayout getStatelayout() {
        return tgyx_statelayout;
    }
}
